package com.sylar.happyreader;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.TextSize;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class WebActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

		String url = this.getIntent().getStringExtra("url");
		
		LinearLayout layout = new LinearLayout(this);
		layout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		
		WebView myWeb = new WebView(this);
		
		layout.addView(myWeb);
		
		setContentView(layout);
		
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
		
		WebSettings wSetting = myWeb.getSettings();
		wSetting.setJavaScriptEnabled(true);
		wSetting.setBuiltInZoomControls(true);
		wSetting.setJavaScriptEnabled(true);
		wSetting.setPluginsEnabled(true);
		wSetting.setSupportMultipleWindows(true);
		wSetting.setSupportZoom(true);
		wSetting.setBlockNetworkImage(false);
		wSetting.setTextSize(TextSize.NORMAL);
		wSetting.setAllowFileAccess(true);
		wSetting.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
		
//		ImageView imageView = (ImageView) findViewById(R.id.titleImage);
//		imageView.setVisibility(View.GONE);
		
		final TextView titleText = (TextView) findViewById(R.id.titleText);
		titleText.setVisibility(View.VISIBLE);
		
		myWeb.setWebViewClient(new WebViewClient(){
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
		});
		
		myWeb.setWebChromeClient(new WebChromeClient() {
			@Override
			public void onProgressChanged(WebView view, int progress) {
				titleText.setText("请等待，内容加载中..." + progress + "%");
				if (progress == 100) {
					titleText.setText(R.string.app_name);
					
				}
			}
			
			

		});

		
		
		myWeb.loadUrl(url);
	}

}
